
# find shaderc_combined
find_package(Vulkan COMPONENTS shaderc_combined REQUIRED)

if(NOT Vulkan_shaderc_combined_FOUND)
  message(FATAL_ERROR "Can't find Vulkan shaderc !")
endif()


add_library(ShaderCompiler INTERFACE)

if(WIN32)
  #add extra ‘d’ if debug
  get_filename_component(Vulkan_shaderc_combined_LIBRARY_Dir ${Vulkan_shaderc_combined_LIBRARY} DIRECTORY  )
  get_filename_component(Vulkan_shaderc_combined_LIBRARY_File_Name ${Vulkan_shaderc_combined_LIBRARY}  NAME_WE )
  get_filename_component(Vulkan_shaderc_combined_LIBRARY_File_Ext ${Vulkan_shaderc_combined_LIBRARY}  EXT    )
  set(Vulkan_shaderc_combined_LIBRARY_WithD ${Vulkan_shaderc_combined_LIBRARY_Dir}/${Vulkan_shaderc_combined_LIBRARY_File_Name}d${Vulkan_shaderc_combined_LIBRARY_File_Ext})

  target_link_libraries(ShaderCompiler INTERFACE  $<$<CONFIG:Debug>:${Vulkan_shaderc_combined_LIBRARY_WithD}>$<$<CONFIG:Release>:${Vulkan_shaderc_combined_LIBRARY}>)
else()
  target_link_libraries(ShaderCompiler INTERFACE  ${Vulkan_shaderc_combined_LIBRARY})
endif()

target_include_directories(ShaderCompiler INTERFACE  ${Vulkan_INCLUDE_DIR})



set(Plugin EngineEditorLib)

#recursively find all c++ file under Source folder
file(GLOB_RECURSE EngineEditorLib_SOURCES "Source/*.cpp")


add_library(${Plugin} SHARED ${EngineEditorLib_SOURCES})

target_include_directories(${Plugin} PUBLIC 
    ${CMAKE_CURRENT_LIST_DIR}/Source/
    ${CMAKE_CURRENT_LIST_DIR}/../EngineCore/Source/
    )


target_link_libraries(${Plugin} PUBLIC EngineCore ShaderCompiler)


#set DEBUG Macro
target_compile_definitions(${Plugin} PUBLIC "$<$<CONFIG:DEBUG>:DEBUG>")

#add export macro
if(WIN32)
  string(TOUPPER ${Plugin} ModuleNameUpperCase)
  target_compile_definitions(${Plugin} PUBLIC "BUILD_${ModuleNameUpperCase}_DLL")
endif()

#set system Macro
if(WIN32)
  target_compile_definitions(${Plugin} PRIVATE "WIN32")
  endif ()

if(LINUX)
  target_compile_definitions(${Plugin} PRIVATE "LINUX")
endif()

if(MACOS)
  target_compile_definitions(${Plugin} PRIVATE "MACOS")
ENDIF ()

if(IOS)
  target_compile_definitions(${Plugin} PRIVATE "IOS")
endif()

if(ANDROID)
  target_compile_definitions(${Plugin} PRIVATE "ANDROID")
endif()


add_custom_target(EngineEditor2Content

    COMMAND ${CMAKE_COMMAND} -E copy_directory 
    ${CMAKE_CURRENT_LIST_DIR}/Content 
    $<$<CONFIG:Debug>:${CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG}/Content/EngineEditor2>$<$<CONFIG:Release>:${CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE}/Content/EngineEditor2>
    COMMENT "Copying EngineEditor2 content(if failed,maybe you are using editor asset)"
    VERBATIM
)

# add_dependencies(EngineEditor2Content ShaderCompilerTool )
add_dependencies(${Plugin} EngineEditor2Content)


add_custom_target(AutoGenerateSourceFile
  #convert all icon to text file
  COMMAND  $<TARGET_FILE:BinaryToText> ${CMAKE_CURRENT_LIST_DIR}/Source/Icons .png
  COMMAND  $<TARGET_FILE:BinaryToText> ${CMAKE_CURRENT_LIST_DIR}/Source/Icons/Microsoft .png
  COMMAND  $<TARGET_FILE:BinaryToText> ${CMAKE_CURRENT_LIST_DIR}/Source/Icons/Google .png
  COMMAND  $<TARGET_FILE:BinaryToText> ${CMAKE_CURRENT_LIST_DIR}/Source/Icons/BoxiconsSolid .png
  COMMAND  $<TARGET_FILE:BinaryToText> ${CMAKE_CURRENT_LIST_DIR}/Source/Icons/tabler .png
  COMMAND  $<TARGET_FILE:BinaryToText> ${CMAKE_CURRENT_LIST_DIR}/Source/Icons/Phosphor .png
  #reflect 
  COMMAND  $<TARGET_FILE:EngineReflectionTool>  
  ${CMAKE_CURRENT_LIST_DIR}/../EngineCore/Source "EngineCore"
  ${CMAKE_CURRENT_LIST_DIR}/Source "EngineEditor"
)

add_dependencies(${Plugin} AutoGenerateSourceFile)

